/*

Frequency of use: 1 2 3 [4] 5 MEDIUM HIGH

Short:
    Singleton ensures that there is one, and only one instance of a class.  Like 
global variables, everybody has access to that instance.  Singleton should be 
used sparingly since the assumption that there should be just one of something 
usually ends up being wrong.  Singleton is hard to write unit tests with.

Long:
    In software engineering, the singleton pattern is a design pattern that is 
used to restrict instantiation of a class to one object. This is useful when 
exactly one object is needed to coordinate actions across the system. The 
concept is sometimes generalized to systems that operate more efficiently when 
only one object exists, or that restrict the instantiation to a certain number 
of objects (say, five). Some consider it an anti-pattern, judging that it is 
overused, introduces unnecessary limitations in situations where a sole instance 
of a class is not actually required, and introduces global state into an 
application.

Information sources:
 - http://calumgrant.net/patterns/index.html
 - http://en.wikipedia.org/wiki/Singleton_pattern
 - http://www.dofactory.com/Patterns/Patterns.aspx
*/

#include <iostream>

class HelloWorld
{
	HelloWorld() { }
	HelloWorld(const HelloWorld&);
public:
	void output()
	{
		std::cout << "Hello world!" << std::endl;
	}
	static HelloWorld & get()
	{
		static HelloWorld singleton;
		return singleton;
	}
};

void hello_world()
{
	HelloWorld::get().output();
}

int main()
{
	hello_world();
	return 0;
}


